import axiosInstance from '@/tools/request'
import type { HardwareDriver } from '@/api/hardware/driver/hardwareDriver.d'
import axios from 'axios'
import { responseDownload } from '@/tools/download'

//hardwareDriverAdd 硬件设备添加
export const hardwareDriverAdd = (hardwareDriver: HardwareDriver) => {
  return axiosInstance({
    url: `/hardwareDriver`,
    method: 'post',
    data: hardwareDriver
  })
}

//hardwareDriverRemove 硬件设备删除
export const hardwareDriverRemove = (hardwareDriverId: number) => {
  return axiosInstance({
    url: `/hardwareDriver/${hardwareDriverId}`,
    method: 'delete'
  })
}

//hardwareDriverModify 硬件设备修改
export const hardwareDriverModify = (hardwareDriver: HardwareDriver) => {
  return axiosInstance({
    url: `/hardwareDriver`,
    method: 'put',
    data: hardwareDriver
  })
}

//hardwareDriverList 硬件设备列表
export const hardwareDriverList = (hardwareDriver: HardwareDriver, params: any) => {
  return axiosInstance({
    url: '/hardwareDriver/list',
    method: 'post',
    params: params,
    data: hardwareDriver
  })
}

//hardwareDriverById 硬件设备查询通过ID
export const hardwareDriverById = (hardwareDriverId: number) => {
  return axiosInstance({
    url: `/hardwareDriver/${hardwareDriverId}`,
    method: 'get'
  })
}

//hardwareDriverRemoveBatch 硬件设备批量删除
export const hardwareDriverRemoveBatch = (ids: any[]) => {
  return axiosInstance({
    url: `/hardwareDriver/batchDelete`,
    method: 'delete',
    params: {
      ids: ids
    }
  })
}


//hardwareDriverBatchImportTemplateDownload 硬件设备模板下载
export const hardwareDriverBatchImportTemplateDownload = () => {
  axios({
    url: '/api/hardwareDriver/templateDownload',
    method: 'get',
    responseType: 'blob',
    headers: {
      token: localStorage.getItem('token')
    }
  }).then(response => {
    responseDownload(response)
  })
}

//hardwareDriverBatchExport 硬件设备批量导出
export const hardwareDriverBatchExport = (ids: any[]) => {
  axios({
    url: '/api/hardwareDriver/export',
    method: 'get',
    responseType: 'blob',
    params: {
      ids: ids
    },
    headers: {
      token: localStorage.getItem('token')
    }
  }).then(response => {
    responseDownload(response)
  })

}

//hardwareDriverRemoveBatch 硬件设备批量导入
export const hardwareDriverBatchImport = (file: File) => {
  const formData = new FormData()
  formData.append('file', file)
  return axiosInstance({
    url: `/hardwareDriver/import`,
    method: 'delete',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data: formData
  })
}
